package com.ruoyi.web.sso.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.sso.domain.AppEdition;
import com.ruoyi.web.sso.service.IAppEditionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * APP版本Controller
 * 
 * @author ruoyi
 * @date 2023-04-13
 */
@Controller
@RequestMapping("/sso/appEdition")
public class AppEditionController extends BaseController
{
    private String prefix = "sso/appEdition";

    @Autowired
    private IAppEditionService appEditionService;

    @RequiresPermissions("sso:appEdition:view")
    @GetMapping()
    public String appEdition()
    {
        return prefix + "/appEdition";
    }

    /**
     * 查询APP版本列表
     */
    @RequiresPermissions("sso:appEdition:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppEdition appEdition)
    {
        startPage();
        List<AppEdition> list = appEditionService.selectAppEditionList(appEdition);
        return getDataTable(list);
    }

    /**
     * 导出APP版本列表
     */
    @RequiresPermissions("sso:appEdition:export")
    @Log(title = "APP版本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppEdition appEdition)
    {
        List<AppEdition> list = appEditionService.selectAppEditionList(appEdition);
        ExcelUtil<AppEdition> util = new ExcelUtil<AppEdition>(AppEdition.class);
        return util.exportExcel(list, "APP版本数据");
    }

    /**
     * 新增APP版本
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存APP版本
     */
    @RequiresPermissions("sso:appEdition:add")
    @Log(title = "APP版本", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AppEdition appEdition)
    {
        return toAjax(appEditionService.insertAppEdition(appEdition));
    }

    /**
     * 修改APP版本
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        AppEdition appEdition = appEditionService.selectAppEditionById(id);
        mmap.put("appEdition", appEdition);
        return prefix + "/edit";
    }

    /**
     * 修改保存APP版本
     */
    @RequiresPermissions("sso:appEdition:edit")
    @Log(title = "APP版本", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppEdition appEdition)
    {
        return toAjax(appEditionService.updateAppEdition(appEdition));
    }

    /**
     * 删除APP版本
     */
    @RequiresPermissions("sso:appEdition:remove")
    @Log(title = "APP版本", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(appEditionService.deleteAppEditionByIds(ids));
    }
}
